
{#无手机验证码#}
username = request.POST.get('uname')
        password = request.POST.get('upassword')
        new_password = makepwd(password)
        user = User.objects.filter(username=username, userpasswd=new_password)
        # 先判断验证码
        codedata = request.POST.get('yzmcode')
        # print(codedata)
        # 得到session的验证码
        scodedata = request.session.get('code')
        print(scodedata)
        if codedata == scodedata:
            if user.exists():
                # 同时再设置session过去首页
                request.session['uname'] = username
                request.session['upassword'] = new_password
                return redirect(reverse('App:index'))
            else:
                data = {
                    'code': -1,
                    'msg': '用户名或密码错误，请重写输入',
                    'wait': 3,
                    'url': "/App/login/"
                }
                return render(request, 'notice.html', data)
        else:
            data = {
                'code': -2,
                'msg': '验证码错误，请重写输入',
                'wait': 3,
                'url': "/App/login/"
            }
            return render(request, 'notice.html', data)



{# # #有手机验证码#}
        yzm = request.session.get('yzm')
        yzm = str(yzm)

        code = request.POST.get('sms')
        print(yzm, code)
        # 手机验证码
        if yzm == code:
            # 去数据库判断用户名密码是否正确
            username = request.POST.get('uname')
            password = request.POST.get('upassword')
            new_password = makepwd(password)
            user = User.objects.filter(username=username, userpasswd=new_password)
            # 先判断验证码
            codedata = request.POST.get('yzmcode')
            # print(codedata)
            # 得到session的验证码
            scodedata = request.session.get('code')
            print(scodedata)
            if codedata == scodedata:
                if user.exists():
                    # 同时再设置session过去首页
                    request.session['uname'] = username
                    request.session['upassword'] = new_password
                    return redirect(reverse('App:index'))
                else:
                    data = {
                        'code': -1,
                        'msg': '用户名或密码错误，请重写输入',
                        'wait': 3,
                        'url': "/App/login/"
                    }
                    return render(request, 'notice.html', data)
            else:
                data = {
                    'code': -2,
                    'msg': '验证码错误，请重写输入',
                    'wait': 3,
                    'url': "/App/login/"
                }
                return render(request, 'notice.html', data)
        else:
            data = {
                'code': -3,
                'msg': '手机验证码错误，请重写输入',
                'wait': 3,
                'url': "/App/login/"
            }
            return render(request, 'notice.html', data)